home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT57.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  9.1 KB  |  282 lines

  1. /*
  2. ==============================================================================
  3.               WordUp Graphics Toolkit Version 5.0                     
  4.                  Demonstration Program 57                         
  5.                                           
  6.   This program uses the scrolling library to demonstrate some of the          
  7.   possible configurations of the scrolling windows.                           
  8.                                           
  9.   *** PROJECT ***                                                             
  10.   This program requires the files WGT5_WC.LIB and WSCR_WC.LIB to be linked.   
  11.                                           
  12.   *** DATA FILES ***                                                          
  13.   TEST1-TEST4.SPR, TEST1-TEST4.WMP         
  14.                                WATCOM C++ VERSION 
  15. ==============================================================================
  16. */
  17.  
  18. #include <dos.h>
  19. #include <wgt5.h>
  20. #include <wgtscrol.h>
  21.  
  22.  
  23. /* Keyboard control codes */
  24. #define LEFT 75
  25. #define RIGHT 77
  26. #define UP 72
  27. #define DOWN 80
  28. #define ESC 1
  29.  
  30. #define NUM_TILES 5
  31.  
  32. block tiles0[NUM_TILES+1];      /* 4 block array to hold our sets of tiles */
  33. block tiles1[NUM_TILES+1];
  34. block tiles2[NUM_TILES+1];
  35. block tiles3[NUM_TILES+1];
  36.  
  37. short tiletypes0[256];            /* Tile types for each window */
  38. short tiletypes1[256];
  39. short tiletypes2[256];
  40. short tiletypes3[256];
  41.  
  42. scrollsprite wobject[5];        /* No objects are used in this demo, but a
  43.                    scrollsprite structure is needed to load
  44.                    the map. */
  45.  
  46. short window_on[4];
  47. block sprites[5];
  48. wgtmap map0, map1, map2, map3;
  49.  
  50. short setup;
  51.  
  52. short oldmode;             /* Previous graphics mode */
  53. color pal[256];            /* A common palette for all sprites/tiles */
  54. short xsize[4], ysize[4];  /* The size of the tiles in our map */
  55. char c;
  56. int timer;
  57. short movex, movey;
  58.  
  59. void loadsprites (void);
  60. void loadmaps (void);
  61. void find_tile_sizes (void);
  62. void start_scroll (void);
  63. void close_files (void);
  64.  
  65.  
  66. void timerctr (void)
  67. {
  68.   timer++;
  69. }
  70.  
  71.  
  72. void main (void)
  73. {
  74.  int frames = 0;
  75.  
  76.  oldmode = wgetmode ();
  77.  
  78.  printf ("WGT v5.0  Scrolling Possibilities Demo\n");
  79.  printf ("This demo is meant to show the versatility of WGT's scrolling\n");
  80.  printf ("library.  It does not show all of the possible scrolling combinations\n");
  81.  printf ("but it gives you some setups that you can base a game around.\n\n");
  82.  printf ("The WGT v5.0 for Watcom system allows up to 50 maps used in any\n");
  83.  printf ("combination of normal and parallax layers. This demo does not\n");
  84.  printf ("make any attempt to illustrate these possibilities (or artwork :)\n\n");
  85.  printf ("Choose your scrolling setup:\n\n");
  86.  printf ("[0] 4 windows\n");
  87.  printf ("[1] 1 window, 1 scrolling level\n");
  88.  printf ("[2] 1 window, 2 scrolling levels\n");
  89.  printf ("[3] 1 window, 3 scrolling levels\n");
  90.  printf ("[4] 1 window, 4 scrolling levels\n");
  91.  printf ("[5] 2 windows, 1 scrolling level, vertical\n");
  92.  printf ("[6] 2 windows, 2 scrolling levels, vertical\n");
  93.  printf ("[7] 2 windows, 1 scrolling level, horizontal\n");
  94.  printf ("[8] 2 windows, 2 scrolling levels, horizontal\n");
  95.  printf ("[9] 2 windows, 1 with 3 levels, the other with 1 level\n");
  96.  
  97.  printf ("Enter your setup:");
  98.  scanf ("%i", &setup);
  99.  
  100.  vga256 ();
  101.  
  102.  loadsprites ();
  103.  find_tile_sizes ();
  104.  
  105.  start_scroll ();
  106.  loadmaps ();
  107.  
  108.  installkbd ();
  109.  timer = 0;
  110.  winittimer ();
  111.  wstarttimer (timerctr, TICKS(100));
  112.  do {
  113.    movex = 0;
  114.    movey = 0;
  115.  
  116.    if (kbdon[UP]) 
  117.        movey = -16;
  118.    if (kbdon[DOWN])
  119.        movey = 16;
  120.    if (kbdon[LEFT])
  121.        movex = -16;
  122.    if (kbdon[RIGHT])
  123.        movex = 16;
  124.  
  125.    if (window_on[0])
  126.        wscrollwindow (0, movex * 1 / 4, movey * 1 / 4);
  127.    if (window_on[1])
  128.        wscrollwindow (1, movex * 2 / 4, movey * 2 / 4);
  129.    if (window_on[2])
  130.        wscrollwindow (2, movex * 3 / 4, movey * 3 / 4);
  131.    if (window_on[3])
  132.        wscrollwindow (3, movex, movey);
  133.  
  134. //   wretrace ();
  135.    switch (setup)
  136.    {
  137.      case 0: wputblock (0, 0, scrollblock[0], NORMAL);
  138.          wputblock (128, 0, scrollblock[1], NORMAL);
  139.          wputblock (0, 100, scrollblock[2], NORMAL);
  140.          wputblock (128, 100, scrollblock[3], NORMAL);
  141.          break;
  142.      case 1:
  143.      case 2:
  144.      case 3:
  145.      case 4: wputblock (0, 0, scrollblock[0], NORMAL); 
  146.          break;
  147.      case 5:
  148.      case 6: wputblock (0, 0, scrollblock[0], NORMAL);
  149.          wputblock (128, 0, scrollblock[1], NORMAL); 
  150.          break;
  151.      case 7:
  152.      case 8: wputblock (0, 0, scrollblock[0], NORMAL);
  153.          wputblock (0, 100, scrollblock[1], NORMAL); 
  154.          break;
  155.      case 9: wputblock (0, 0, scrollblock[0], NORMAL);
  156.          wputblock (128, 0, scrollblock[3], NORMAL); 
  157.          break;
  158.     }
  159.     frames++;
  160.   } while (!kbdon[ESC]);  /* Until ESC is hit */
  161.   wstoptimer ();
  162.   wdonetimer ();
  163.   uninstallkbd ();
  164.   close_files ();
  165.  
  166.   wsetmode (oldmode);
  167.   printf ("Number of Frames: %i\n", frames);
  168.   printf ("Time elapsed:     %7.2f seconds\n", (float)(timer) / 100.0);
  169.   printf ("Frame Rate:       %f\n", (float)frames / ((float)(timer) / 100.0));
  170. }
  171.  
  172.  
  173. void loadsprites (void)
  174. {
  175.   wloadsprites (pal, "test1.spr", tiles0, 1, NUM_TILES);
  176.   wloadsprites (pal, "test2.spr", tiles1, 1, NUM_TILES);
  177.   wloadsprites (pal, "test3.spr", tiles2, 1, NUM_TILES);
  178.   wloadsprites (pal, "test4.spr", tiles3, 1, NUM_TILES);
  179.   wsetpalette (0, 255, pal);
  180. }
  181.  
  182.  
  183. void loadmaps (void)
  184. {
  185.   map0 = wloadmap (0, "test4.wmp", tiletypes0, wobject);
  186.   map1 = wloadmap (1, "test3.wmp", tiletypes1, wobject);
  187.   map2 = wloadmap (2, "test2.wmp", tiletypes2, wobject);
  188.   map3 = wloadmap (3, "test1.wmp", tiletypes3, wobject);
  189.  
  190.   /* If the tilewidth is not 0, the window must have been initialized
  191.      above, so start viewing it at the top left of the map. */
  192.   if (tilewidth[0] > 0)
  193.   {
  194.     wshowwindow (0, 0, 0);
  195.     window_on[0] = 1;
  196.   }
  197.   if (tilewidth[1] > 0)
  198.   {
  199.     wshowwindow (1, 0, 0);
  200.     window_on[1] = 1;
  201.   }
  202.   if (tilewidth[2] > 0)
  203.   {
  204.     wshowwindow (2, 0, 0);
  205.     window_on[2] = 1;
  206.   }
  207.   if (tilewidth[3] > 0)
  208.   {
  209.     wshowwindow (3, 0, 0);
  210.     window_on[3] = 1;
  211.   }
  212. }
  213.   
  214.  
  215. void find_tile_sizes (void)
  216. {
  217.   xsize[0] = wgetblockwidth (tiles0[1]);
  218.   ysize[0] = wgetblockheight (tiles0[1]);
  219.  
  220.   xsize[1] = wgetblockwidth (tiles1[2]);
  221.   ysize[1] = wgetblockheight (tiles1[2]);
  222.  
  223.   xsize[2] = wgetblockwidth (tiles2[1]);
  224.   ysize[2] = wgetblockheight (tiles2[1]);
  225.  
  226.   xsize[3] = wgetblockwidth (tiles3[1]);
  227.   ysize[3] = wgetblockheight (tiles3[1]);
  228. }
  229.  
  230.  
  231. void start_scroll (void)
  232. {
  233.   switch (setup)
  234.   {
  235.     case 0:  winitscroll (0, NORMAL,  -1, 128 / xsize[2], 96 / ysize[2], tiles2);
  236.          winitscroll (1, NORMAL,  -1, 128 / xsize[1], 96 / ysize[1], tiles1);
  237.          winitscroll (2, NORMAL,  -1, 128 / xsize[2], 96 / ysize[2], tiles2);
  238.          winitscroll (3, NORMAL,  -1, 128 / xsize[3], 96 / ysize[3], tiles3); break;
  239.     case 1:  winitscroll (0, NORMAL,  -1, 320 / xsize[3], 192 / ysize[3], tiles3); break;
  240.     case 2:  winitscroll (0, NORMAL,  -1, 320 / xsize[3], 192 / ysize[3], tiles3);
  241.          winitscroll (1, PARALLAX, 0, 320 / xsize[1], 192 / ysize[1], tiles1); break;
  242.     case 3:  winitscroll (0, NORMAL,  -1, 256 / xsize[0], 192 / ysize[0], tiles0);
  243.          winitscroll (1, PARALLAX, 0, 256 / xsize[1], 192 / ysize[1], tiles1);
  244.          winitscroll (2, PARALLAX, 0, 256 / xsize[2], 192 / ysize[2], tiles2); break;
  245.     case 4:  winitscroll (0, NORMAL,  -1, 256 / xsize[0], 192 / ysize[0], tiles0);
  246.          winitscroll (1, PARALLAX, 0, 256 / xsize[2], 192 / ysize[2], tiles2);
  247.          winitscroll (2, PARALLAX, 0, 256 / xsize[1], 192 / ysize[1], tiles1);
  248.          winitscroll (3, PARALLAX, 0, 256 / xsize[3], 192 / ysize[3], tiles3); break;
  249.     case 5:  winitscroll (0, NORMAL,  -1, 128 / xsize[0], 192 / ysize[0], tiles0);
  250.          winitscroll (1, NORMAL,  -1, 128 / xsize[1], 192 / ysize[1], tiles1); break;
  251.     case 6:  winitscroll (0, NORMAL,  -1, 128 / xsize[0], 192 / ysize[0], tiles0);
  252.          winitscroll (1, NORMAL,  -1, 128 / xsize[1], 192 / ysize[1], tiles1);
  253.          winitscroll (2, PARALLAX, 0, 128 / xsize[2], 192 / ysize[2], tiles2);
  254.          winitscroll (3, PARALLAX, 1, 128 / xsize[3], 192 / ysize[3], tiles3); break;
  255.     case 7:  winitscroll (0, NORMAL,  -1, 320 / xsize[2], 96 / ysize[2], tiles2);
  256.          winitscroll (1, NORMAL,  -1, 320 / xsize[1], 96 / ysize[1], tiles1); break;
  257.     case 8:  winitscroll (0, NORMAL,  -1, 320 / xsize[2], 96 / ysize[2], tiles2);
  258.          winitscroll (1, NORMAL,  -1, 320 / xsize[1], 96 / ysize[1], tiles1);
  259.          winitscroll (2, PARALLAX, 0, 320 / xsize[2], 96 / ysize[2], tiles2);
  260.          winitscroll (3, PARALLAX, 1, 320 / xsize[3], 96 / ysize[3], tiles3); break;
  261.     case 9:  winitscroll (0, NORMAL,  -1, 128 / xsize[2], 192 / ysize[2], tiles2);
  262.          winitscroll (1, PARALLAX, 0, 128 / xsize[1], 192 / ysize[1], tiles1);
  263.          winitscroll (2, PARALLAX, 0, 128 / xsize[3], 192 / ysize[3], tiles3);
  264.          winitscroll (3, NORMAL,  -1, 128 / xsize[3], 192 / ysize[3], tiles3); break;
  265.   }                                                                      
  266. }
  267.  
  268.  
  269. void close_files(void)
  270. {
  271.   wfreemap (map0);
  272.   wfreemap (map1);
  273.   wfreemap (map2);
  274.   wfreemap (map3);
  275.   wendscroll (0);
  276.   wendscroll (1);
  277.   wendscroll (2);
  278.   wendscroll (3);
  279. }
  280.  
  281.  
  282.